<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>团队管理</title>
	<%@include file="/WEB-INF/common/static.jsp" %>
	<script type="text/javascript">
		function saveGroup(){
			if($("#groupName").val()==""){
				alert("群组名不能为空");
				return false;
			}
			var userIds = [];
           	$('input[name="username"]').each(function(){
           		if($(this).is(":checked")){
           			userIds.push($(this).val());
           		}
           	});
           	$.post("${ctx}/officeManage/groupManange/addGroup.do",{
	        		groupName : $("#groupName").val(),
	        		userIds : userIds
	        	},function(data){
	        		if(200 == data.code){
	        			alert(data.data);
	        			location.href = "${ctx }/officeManage/groupManange/showHaveGroups.do";
	        		}else{
	        			alert("添加失败！失败原因：" + data.data);
	        		}
	        	},"json")
		}
		
		function checkAllUsers(){
			$(".allchecked").click(function() {
                $('input[name="username"]').prop("checked",true); 
            });
		}
		
		function invertSelect(){
			$('input[name="username"]').each(function(){
        		if($(this).is(":checked")){
        			$(this).prop("checked",false);
        		}else{
        			$(this).prop("checked",true);
        		}
        	})
		}
	</script>
</head>
<body>
    <ul class="nav nav-tabs" role="tablist">
		<li role="presentation"><a
			href="${ctx }/officeManage/groupManange/showHaveGroups.do">查看团队</a></li>
		<li role="presentation" class="active"><a 
			href="${ctx }/officeManage/groupManange/newGroup.do">新建团队</a></li>
	</ul>
	<div class="container" style="margin:0 0 0 25px;">
		<div class="form-horizontal">
			<div class="form-group" style="padding-top:20px;">
				<label class="col-sm-2 control-label">团队名称：</label>
				<div class="col-sm-3">
					<input id="groupName" type="text" class="form-control">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">选择成员：</label>
				<div class="col-sm-8">
					<c:forEach var="currUser" items="${users }" varStatus="i">
						<c:if test="${currUser.id != user.id }">
							<label class="checkbox-inline">
						  		<input type="checkbox" name="username" value="${currUser.id}">${currUser.userName }
							</label>
						</c:if>
					</c:forEach>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="button" class="btn btn-primary allchecked" onclick="checkAllUsers();">全选</button>
					<button type="button" class="btn btn-primary scrollchecked" onclick="invertSelect();">反选</button>
					<button type="button" class="btn btn-primary namesava" onclick="saveGroup();">保存</button>
				</div>
			</div>	
		</div>
	</div>
</body>
</html>